/*
This file is part of Jumpers.

Jumpers is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Jumpers is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Jumpers.  If not, see <http://www.gnu.org/licenses/>.
*/
package org.chaoticengine.cgll.entity.component;

//~--- non-JDK imports --------------------------------------------------------

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.state.StateBasedGame;

//~--- JDK imports ------------------------------------------------------------

import java.util.ArrayList;
import java.util.Map;

/**
 * A component with some logic that must be called on every iteration
 * through the game loop.
 *
 * @author Matt v.d. Westhuizen
 *
 */
public abstract class ActiveComponent extends Component implements IActiveComponent {
    protected ArrayList<Command> activeCommands = null;

    public ActiveComponent() {
        super();
        this.activeCommands = new ArrayList<Command>();
    }

    /** Commands added by this component. */
    public abstract Map<String, Command> getCommands();

    public void update(GameContainer gc, StateBasedGame sb, int delta) {
        for (int i = 0; i < this.activeCommands.size(); i++) {
            this.activeCommands.get(i).doAction(delta);
        }
    }

    public void enableCommand(Command c) {
        this.activeCommands.add(c);
    }

    public void disableCommand(Command c) {
        this.activeCommands.remove(c);
    }

    /**
     * Child classes can override this to make initialisation calculations that
     * depend upon having their owner set.
     */
    @Override
    public void onSetOwner() {

    }
}


//~ Formatted by Jindent --- http://www.jindent.com
